package com.pig.consume.controller;

import com.pig.common.JsonUtils;
import com.pig.rpc.client.IHello1;
import com.pig.rpc.client.IHello2;
import com.pig.rpc.client.dto.Person;
import com.pig.rpc.client.dto.QueryPara;
import com.pig.rpc.client.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ThreadLocalRandom;

/**
 * @author lizhiwei
 */
@RestController
public class ConsumeController {
    @Autowired
    IHello1 hello1;
    @Autowired
    IHello2 hello2;

    @RequestMapping("/hello1/{name}")
    public String hello1(@PathVariable String name) {
        QueryPara queryPara = new QueryPara(1L,name);
        queryPara.setId(ThreadLocalRandom.current().nextLong());
        queryPara.setName(name);
        Result<Person> hello = hello1.hello(queryPara, false);
        return JsonUtils.objToJsonStr(hello);
    }

    @RequestMapping("/hello2/{name}")
    public String hello2(@PathVariable String name) {
        return hello2.hello(name);
    }
}
